<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片跟随鼠标移动</title>
    <style>
        #myImage {
            position: absolute;
            width: 50px;
            height: 50px;
            /* 初始位置 */
            left: 0;
            top: 0;
        }
    </style>
</head>
<body>
    <img src="1.png" id="myImage" alt="图片">

    <script>
        const img = document.getElementById('myImage');

        document.addEventListener('mousemove', (e) => {
            // 获取鼠标的坐标
            const mouseX = e.clientX;
            const mouseY = e.clientY;

            // 设置图片的位置
            img.style.left = (mouseX + 10) + 'px';
            img.style.top = (mouseY + 10) + 'px';
        });
    </script>
</body>
</html>